package com.watson.activity;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.InputType;
import android.text.TextUtils;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.widget.AppCompatButton;

import com.google.gson.Gson;
import com.watson.BaseActivity;
import com.watson.MainActivity;
import com.watson.R;
import com.watson.http.CommonHttpConsts;
import com.watson.http.HttpCallbackWdss;
import com.watson.http.HttpClient;
import com.watson.utils.DialogUitl;
import com.watson.utils.LogUtils;
import com.watson.utils.SPUtils;
import com.watson.utils.StringUtils;
import com.watson.utils.ToastUtil;

import java.util.HashMap;
import java.util.Map;

public class RegisterActivity extends BaseActivity {
    private AppCompatButton login_btn;
    private String userName, password, password2;
    private EditText ed_userName, ed_password, ed_password2;
    private ImageView imgEye, imgEye2;
    private TextView tvTitle;
    private boolean isEye = false;
    private boolean isEye2 = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        statusbar4();

        tvTitle = findViewById(R.id.tvTitle);
        tvTitle.setText("账户注册");
        findViewById(R.id.imgBack).setOnClickListener(v -> finish());
        imgEye = findViewById(R.id.imgEye);
        imgEye2 = findViewById(R.id.imgEye2);

        initView();
    }

    private void initView() {
        login_btn = findViewById(R.id.login_btn);
        ed_userName = findViewById(R.id.ed_userName);
        ed_password = findViewById(R.id.ed_password);
        ed_password2 = findViewById(R.id.ed_password2);

        imgEye.setOnClickListener(v -> {
            if (isEye) {
                isEye = false;
                ed_password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                imgEye.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.icon_eye_b));
            } else {
                isEye = true;
                ed_password.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                imgEye.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.icon_eye_z));
            }
        });

        imgEye2.setOnClickListener(v -> {
            if (isEye2) {
                isEye2 = false;
                ed_password2.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                imgEye2.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.icon_eye_b));
            } else {
                isEye2 = true;
                ed_password2.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                imgEye2.setImageDrawable(mContext.getResources().getDrawable(R.mipmap.icon_eye_z));
            }
        });

        login_btn.setOnClickListener(v -> {
            userName = ed_userName.getText().toString().trim();
            if (StringUtils.isEmpty(userName)) {
                ToastUtil.show("请输入账号!");
                return;
            }
            password = ed_password.getText().toString().trim();
            if (TextUtils.isEmpty(password)) {
                ToastUtil.show("请输入密码!");
                return;
            }
            password2 = ed_password2.getText().toString().trim();
            if (TextUtils.isEmpty(password2)) {
                ToastUtil.show("请再次输入密码!");
                return;
            }
            if (!password.equals(password2)) {
                ToastUtil.show("两次密码输入不一致!");
                return;
            }
        });
    }
}
